#!/usr/bin/env python3
# -*- coding: utf-8 -*-

class InterpretationAgent:
    """解释智能体：负责卦象解释"""
    def __init__(self):
        self.hexagrams = self._load_hexagram_data()
    
    def _load_hexagram_data(self):
        """加载64卦数据"""
        return {
            1: {"name": "乾为天", "symbol": "䷀", "meaning": "元亨利贞", "judgment": "大哉乾元，万物资始，乃统天。"},
            2: {"name": "坤为地", "symbol": "䷁", "meaning": "元亨，利牝马之贞", "judgment": "至哉坤元，万物资生，乃顺承天。"},
            # ... 其他卦数据省略
            64: {"name": "火水未济", "symbol": "䷿", "meaning": "亨，小狐汔济", "judgment": "未济，亨；柔得中也。"}
        }
    
    def interpret_hexagram(self, hex_num):
        """解释主卦"""
        hex_info = self.hexagrams.get(hex_num, {})
        return {
            "name": hex_info.get("name", "未知卦象"),
            "symbol": hex_info.get("symbol", ""),
            "meaning": hex_info.get("meaning", "无卦辞"),
            "judgment": hex_info.get("judgment", "无彖传")
        }
    
    def interpret_changing_lines(self, hex_num, changing_lines):
        """解释变爻"""
        line_meanings = []
        for i, changing in enumerate(changing_lines):
            if changing:
                line_meanings.append(self._get_line_meaning(hex_num, i+1))
        return line_meanings
    
    def _get_line_meaning(self, hex_num, line):
        """获取爻辞解释"""
        meanings = {
            1: "初爻: 潜龙勿用",
            2: "二爻: 见龙在田",
            3: "三爻: 君子终日乾乾",
            4: "四爻: 或跃在渊",
            5: "五爻: 飞龙在天",
            6: "上爻: 亢龙有悔"
        }
        return meanings.get(line, "无爻辞解释")